<?php
error_reporting(E_ALL ^ E_NOTICE);
require_once('config.php');
$id_kode = (int) filter($_POST['id_kode']);
$id_formula = (int) filter($_POST['id_formula']);

$return_arr = array();

if(!empty($id_kode)){
		$fetch = mysql_query("SELECT * FROM tb_kode_bb WHERE id_kode = '" . mysql_real_escape_string($id_kode) . "' "); 
		$ono = mysql_num_rows($fetch);
		/* Retrieve and store in array the results of the query.*/
		while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) {
			$row_array['id_kode'] = $row['id_kode'];
			$row_array['kode'] = $row['kode'];
			$row_array['satuan'] = $row['satuan'];	
			$row_array['nama'] = $row['nama'];					
	        array_push($return_arr,$row_array);
	    }
}elseif (!empty($id_formula)) {
		$fetch = mysql_query("SELECT * FROM tb_formula a, tb_jns_barang b WHERE a.id_jns_brg=b.id_jns_brg AND id_formula = '" . mysql_real_escape_string($id_formula) . "' "); 
		$ono = mysql_num_rows($fetch);
		/* Retrieve and store in array the results of the query.*/
		while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) {			
			$row_array['jumlah'] = $row['satuan_terkecil'];	
			$row_array['jumlah_per_karton'] = $row['satuan_per_karton'];
			$row_array['types'] = $row['type'];	
			$row_array['id_formula'] = $row['id_formula'];		
			$row_array['id_jns_brg'] = $row['id_jns_brg'];
			$row_array['nama_brg'] = $row['nama_brg'];
	        array_push($return_arr,$row_array);
	    }
}


echo json_encode($return_arr);
?>